package models

import (
	"gitee.com/xuxinzhi2206/corehub/database/mysql"
	"gorm.io/gorm"
)

type Order struct {
	gorm.Model
	OrderNo     string  `json:"order_no" gorm:"type:varchar(21);comment:订单编号"`
	OrderCount  float64 `json:"order_count" gorm:"type:decimal(10, 2);comment:订单总价"`
	OrderNum    int     `json:"order_num" gorm:"type:int(11);comment:订单商品数量"`
	GoodsId     int     `json:"goods_id" gorm:"type:int(11);comment:商品id"`
	UserId      int     `json:"user_id" gorm:"type:int(11);comment:用户id"`
	CreatedAt   string  `json:"create_at" gorm:"type:varchar(20);comment:下单时间"`
	OrderStatus int     `json:"order_status" gorm:"type:tinyint(4);comment:状态,已完成1，已取消2，已付款3，待发货4"`
}

func (o *Order) List() (info []Order, err error) {
	return info, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Table("order").Find(&info).Error
	})
}

func (o *Order) Add() (info *Order, err error) {
	return info, mysql.WithMysql(func(db *gorm.DB) error {
		return db.Table("order").Create(&info).Error
	})
}
